#ifndef __BSP_CAN_H
#define __BSP_CAN_H
#include "main.h"
#include "can.h"
#include <string.h>

// 各个电机向总线反馈数据时的帧头
#define MOTOR_RX_ID_1				0x11
#define MOTOR_RX_ID_2				0x12
#define MOTOR_RX_ID_3				0x13
#define MOTOR_RX_ID_4				0x14
#define MOTOR_RX_ID_5				0x205
#define MOTOR_RX_ID_6				0x206

// 送到各个电机的地址
#define MOTOR_TX_ID_1				0x001
#define MOTOR_TX_ID_2				0x002
#define MOTOR_TX_ID_3				0x003
#define MOTOR_TX_ID_4				0x004
#define MOTOR_TX_ID_5				0x05
#define MOTOR_TX_ID_6			  0x06

typedef CAN_HandleTypeDef hcan_t;

extern uint8_t can_rx_data[6][8];

void BSP_CAN_Init(void);
void CAN_Filter_Init(void);
uint8_t BSP_CAN_SendData(CAN_HandleTypeDef *hcan, uint16_t id, uint8_t *data, uint32_t len);
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan);
void BSP_CAN2_RX_Callback(CAN_HandleTypeDef *hcan);
uint8_t canx_receive(hcan_t *hcan, uint16_t *rec_id, uint8_t *buf);
uint8_t canx_send_data(CAN_HandleTypeDef *hcan, uint16_t id, uint8_t *data, uint32_t len);
void BSP_CAN_RxCallback(void);


// typedef struct {
//   uint8_t data[6][8];
//   volatile uint8_t ready_flag;
// } can_buffer_t;

// extern can_buffer_t can_rx_buffers[2];
// extern volatile uint8_t can_active_buffer;

#endif
